package com.zhangdi.dwcommons.response;

import com.zhangdi.dwcommons.enums.ErrorCode;

public class ResponseUtil {

    public static Response error(String msg) {
        Response resultBean = new Response();
        resultBean.setCode(ErrorCode.error.getCode());
        resultBean.setMsg(msg);
        return resultBean;
    }

    public static Response error(ErrorCode code) {
        Response resultBean = new Response();
        resultBean.setCode(code.getCode());
        resultBean.setMsg(code.name());
        return resultBean;
    }

    public static Response error(ErrorCode code, String msg) {
        Response resultBean = new Response();
        resultBean.setCode(code.getCode());
        resultBean.setMsg(msg);
        return resultBean;
    }

    public static Response success() {
        return new Response();
    }

    public static <T> Response<T> success(String msg, T data) {
        Response<T> resultBean = new Response<T>();
        resultBean.setMsg(msg);
        resultBean.setData(data);
        return resultBean;
    }

    public static <T> Response<T> success(T data) {
        Response<T> resultBean = new Response<T>();
        resultBean.setData(data);
        return resultBean;
    }
}
